package com.tencent.qcloud.tuikit.tuiconversation.Dialog;


import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.tencent.qcloud.tuicore.util.ScreenUtil;
import com.tencent.qcloud.tuikit.tuiconversation.R;

public class TipsDialog {
    private Dialog dialog;
    private TextView title;
    private TextView content;
    private View cancel;
    private View sure;
    private OnSureClick listener;
    private Object data;

    public TipsDialog(Context context) {
        dialog = new Dialog(context);
        dialog.setContentView(R.layout.dialog_tips);
        title = dialog.findViewById(R.id.title);
        content = dialog.findViewById(R.id.content);
        cancel = dialog.findViewById(R.id.cancel_btn);
        sure = dialog.findViewById(R.id.sure_btn);

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                if (listener != null) {
                    dialog.dismiss();
                    listener.onSureClick(data);
                }
            }
        });
    }

    public void setTitle(String str) {
        title.setText(str);
    }

    public void setContent(String str) {
        content.setText(str);
    }

    public void setSureClick(OnSureClick listener) {
        this.listener = listener;
    }

    public void setData(Object o) {
        data = o;
    }

    public void show() {
        dialog.show();

        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
        p.width = (int) (ScreenUtil.getScreenWidth(dialog.getContext()) * 0.9);
        dialog.getWindow().setAttributes(p);
    }

    public void dismiss() {
        dialog.dismiss();
    }

    public interface OnSureClick {
        void onSureClick(Object data);
    }
}
